﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using BusinessLayer;
using BusinessLayer.Auction;
using BusinessLayer.Auction.Models;
using Auction.Models;
using Telerik.Web.Mvc;

namespace Auction.Controllers
{
    public class HomeController : Controller
    {
        [GridAction]
        public ActionResult Index()
        {
            var model = new Auction.Models.AuctionSearchModel();
            List<AuctionCountryModel> listCoutryModel = new AuctionBL().GetAllAuctionCountry();
            listCoutryModel.Insert(0, new AuctionCountryModel { Country = "All countries ----------" });
            model.ListAuctionCountry = listCoutryModel;

            List<AuctionHouseModel> listAuctionHouseModel = new AuctionBL().GetAllAuctionHouse();
            listAuctionHouseModel.Insert(0, new AuctionHouseModel { AuctionHouse = "All House ----------" });
            foreach (var item in listAuctionHouseModel)
            {
                item.AuctionHouse = HttpUtility.HtmlDecode(item.AuctionHouse);
            }
            model.ListAuctionHouse = listAuctionHouseModel;
            int total = 1;
            List<AuctionModel> listAuctionModel = new AuctionBL().Search("", "", "", 1, 10000, out total);

            foreach (var item in listAuctionModel)
            {
                item.AuctionHouse = HttpUtility.HtmlDecode(item.AuctionHouse);
            }
            GridModel<AuctionModel> list = new GridModel<AuctionModel>();
            list.Data = listAuctionModel;
            model.ListAuction = list;
            return View("Index", model);
        }
        [GridAction]
        public ActionResult GetWikiPages()
        {
            int total = 1;
            List<AuctionModel> listAuctionModel = new AuctionBL().Search("", "", "", 1, 15, out total);

            foreach (var item in listAuctionModel)
            {
                item.AuctionHouse = HttpUtility.HtmlDecode(item.AuctionHouse);

            }

            return View(new GridModel<AuctionModel>
            {
                Data = listAuctionModel
            });
        }
    }
}
